package com.droidnetrun.plugin.demo;

import java.lang.reflect.Method;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Toast;
import dalvik.system.DexClassLoader;

public class LoadApk1Activity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_UP) {
			try {
				testaa();
			} catch (Throwable e) {
				Toast.makeText(this, e + "", 1).show();
				e.printStackTrace();
			}
		}
		return super.onTouchEvent(event);
	}

	public void testaa() throws Throwable {
		DexClassLoader loader = new DexClassLoader("/sdcard/auto_apk/loadApk2.apk", "/sdcard", null, getClassLoader());
		try {
			Class c = loader.loadClass("com.test.HelloView");
			Object obj = c.newInstance();
			Method m = c.getDeclaredMethod("show", Activity.class);
			String str = (String) m.invoke(obj, this);
			Toast.makeText(this, str + "", 1).show();
		} catch (Throwable e) {
			Toast.makeText(this, e + "", 1).show();
			e.printStackTrace();
		}
	}
}